<!--
/**
* Author: txj
* Date: 2023年8月15日10:12:20 
* Desc:  卖品item
*/
-->
<template>
  <view class="nav-right-item">
    <image class="image w180 h180" :src="item.imageUrl" />
    <view class="flex-1">
      <view class="fs28 fc3 b">{{ item.name }}</view>
      <view v-if="item.goodsDesc" class="fs24 fc6 mt15 mb15">{{ item.goodsDesc }}</view>
      <view v-if="useCoupon" class="icon">券兑换</view>
      <price :price="item.salePrice" unit-size="24" price-size="38" color="#333"></price>
    </view>
    <view v-if="!useCoupon" class="item-money item-money-end">
      <yy-stepper v-model="num" :min="0" :max="item.stockType === '1' ? 9999 : item.stock" @change="changeNum(item)" />
    </view>
    <view v-if="useCoupon" class="item-money">
      <view class="delete" @click="deleteCoupon(item)"></view>
      <view class="fc3 fs28">{{ item.coupons.length }} 份</view>
    </view>
  </view>
</template>

<script>
  import Price from '@/components/Price'
  export default {
    // 挂载组件
    components: { Price },
    // 数据
    data() {
      return {}
    },
    props: {
      itemData: {
        type: Object
      },
      useCoupon: {
        type: Boolean,
        default: false
      },
      value: {
        type: [Number, String]
      }
    },

    // 挂载方法
    methods: {
      changeNum(item) {
        console.log('changeNum', item)
        console.log('changeNum itemData', this.itemData)
      },
      deleteCoupon(item) {
        this.$emit('deleteCoupon', item.coupons)
      }
    },
    computed: {
      num: {
        set(v) {
          this.$emit('input', v)
        },
        get() {
          return this.value
        }
      },
      item() {
        return this.itemData
      }
    }
  }
</script>
<style lang="scss" scoped>
  .nav-right-item {
    width: 100%;
    box-sizing: border-box;
    display: flex;
    padding: 20rpx;
    background: #fff;
    .image {
      margin-right: 20rpx;
    }
    .icon {
      margin-bottom: 15rpx;
      padding: 3rpx 5rpx;
      text-align: center;
      background: #ffa800;
      border-radius: 8rpx;
      width: 90rpx;
      font-size: 18rpx;
      color: #ffffff;
    }
    .item-money {
      display: flex;
      align-items: flex-end;
      justify-content: space-between;
      flex-direction: column;
      padding-bottom: 10rpx;
      .delete {
        width: 30rpx;
        height: 30rpx;
        background: url('https://public-oss-file.zmaxfilm.com/applet/img/film-oxygen-uniapp/close.png') no-repeat;
        background-size: 100%;
      }
    }
    .item-money-end {
      justify-content: flex-end;
    }
  }
</style>
